﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Notepad_X.Components;
using Notepad_X.Classes;

namespace Notepad_X.Dialogs
{
    public partial class OptionsDialog : Form
    {
        private Main main = Notepad_X.Static.MainInstance;

        public Settings CurrentSettings;

        private MenuPanel CurrentMenuPanel;

        public OptionsDialog()
        {
            InitializeComponent();
        }


        private void OptionsDialog_Load(object sender, EventArgs e)
        {
            CurrentMenuPanel = null;
            CurrentSettings = Main.app_settings;

            Boolean UpdateIcons = false;

            if (Main.app_settings.icons != "default")
            {
                UpdateIcons = true;
            }
            Notepad_X.Components.Static.UpdateFormControls(this, UpdateIcons);

            MenuButtonCollection MenuCollection = new MenuButtonCollection();
            MenuCollection.AddControl(Menu_general);
            MenuCollection.AddControl(Menu_language);
            MenuCollection.AddControl(Menu_toolbars);
            MenuCollection.AddControl(Menu_shortcuts);
            MenuCollection.AddControl(Menu_plugins);
            MenuCollection.AddControl(Menu_updates);
            MenuCollection.AddControl(Menu_icons);
            MenuCollection.AddControl(Menu_highlighters);
            MenuCollection.AddControl(Menu_download);

            int PositionIndex = 0;
            foreach (MenuButton C in MenuCollection)
            {
                int W = GetSizeMenuButton(C);
                if (W < 25) { W = 25; }
                C.Size = new Size(W, C.Size.Height);
                //C.Location = new Point(PositionIndex, C.Location.Y);
                PositionIndex += (W + 2);
            }

            if (PositionIndex < ((double)(MainMenuContainer.Width * 0.9)))
            {
                int plus = (int)((double)(MainMenuContainer.Width - PositionIndex) / MenuCollection.Count);
              
                foreach (MenuButton C in MenuCollection)
                {
                    C.Size = new Size(C.Size.Width + plus, C.Size.Height);
                }
            }

            if (PositionIndex > MainMenuContainer.Width + 15)
            {
                foreach (MenuButton C in MenuCollection)
                {
                    C.Font = new Font(C.Font.FontFamily, 7.5f);
                    int W = GetSizeMenuButton(C);
                    if (W < 25) { W = 25; }
                    C.Size = new Size(W, C.Size.Height);
                }
            }
        }
        private int GetSizeMenuButton(MenuButton C)
        {
            return ((int)(C.Text.Length * C.Font.Size - 6.5));
        }


        private void MenuItemClick(object sender, EventArgs e)
        {
          
          //  if (Panel_general == null)
          //  {
          //      CreatePanel_general();
          //  }
          //  Panel.Controls.Add(Panel_general);
            this.Controls.Remove(Panel);

            Options.OptionsDialog_Gen General = new Notepad_X.Dialogs.Options.OptionsDialog_Gen(this);

            General.Dock = DockStyle.Fill;
            General.BackColor = SystemColors.ControlLightLight;
            this.Controls.Add(General);
            General.BringToFront();
        }

        private void Panel_Paint(object sender, PaintEventArgs e)
        {

        }

        private void MenuItemClick(object sender, UICuesEventArgs e)
        {

        }
    }
}
